package com.bysj.studentsystem.service.impl;

import com.bysj.studentsystem.entity.SysRewardAssistedLoan;
import com.bysj.studentsystem.dao.SysRewardAssistedLoanDao;
import com.bysj.studentsystem.service.SysRewardAssistedLoanService;
import com.bysj.studentsystem.vo.SysRewardAssistedLoanVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.swing.plaf.synth.SynthScrollBarUI;
import java.util.Date;
import java.util.List;

/**
 * (SysRewardAssistedLoan)表服务实现类
 *
 * @author makejava
 * @since 2024-03-09 16:51:49
 */
@Service("sysRewardAssistedLoanService")
public class SysRewardAssistedLoanServiceImpl implements SysRewardAssistedLoanService {
    @Resource
    private SysRewardAssistedLoanDao sysRewardAssistedLoanDao;

    @Autowired
    private UserDetailsServiceImpl userDetailsService;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SysRewardAssistedLoan queryById(Integer id) {
        return this.sysRewardAssistedLoanDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param sysRewardAssistedLoan 筛选条件
     * @return 查询结果
     */
    @Override
    public PageInfo<SysRewardAssistedLoanVO> queryByPage(SysRewardAssistedLoan sysRewardAssistedLoan, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SysRewardAssistedLoanVO> list = this.sysRewardAssistedLoanDao.queryList(sysRewardAssistedLoan);
        return new PageInfo<>(list);
    }

    /**
     * 新增数据
     *
     * @param sysRewardAssistedLoan 实例对象
     * @return 实例对象
     */
    @Override
    public SysRewardAssistedLoan insert(SysRewardAssistedLoan sysRewardAssistedLoan) {
        sysRewardAssistedLoan.setCreateTime(new Date());
        sysRewardAssistedLoan.setApplyStatus("1");
        sysRewardAssistedLoan.setCreateBy(userDetailsService.getCurrentUserId());
        this.sysRewardAssistedLoanDao.insert(sysRewardAssistedLoan);
        return sysRewardAssistedLoan;
    }

    /**
     * 修改数据
     *
     * @param sysRewardAssistedLoan 实例对象
     * @return 实例对象
     */
    @Override
    public SysRewardAssistedLoan update(SysRewardAssistedLoan sysRewardAssistedLoan) {
        sysRewardAssistedLoan.setUpdateTime(new Date());
        sysRewardAssistedLoan.setUpdateBy(userDetailsService.getCurrentUserId());
        this.sysRewardAssistedLoanDao.update(sysRewardAssistedLoan);
        return this.queryById(sysRewardAssistedLoan.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.sysRewardAssistedLoanDao.deleteById(id) > 0;
    }
}
